package com.liunian.algorithmstudy.greedy;

import java.util.Arrays;

public class Candy135 {

	public int candy(int[] ratings) {
		int len = ratings.length;
		int[] candy = new int[len];
		for (int i = 1; i < len; i++) {
			if (ratings[i] > ratings[i - 1]) {
				candy[i] = Math.max(candy[i], candy[i - 1] + 1);
			}
		}
		for (int i = len - 2; i >= 0; i--) {
			if (ratings[i] > ratings[i + 1]) {
				candy[i] = Math.max(candy[i], candy[i + 1] + 1);
			}
		}
		return Arrays.stream(candy).sum() + len;
	}

	public static void main(String[] args) {
		Candy135 candy = new Candy135();
		System.out.println(candy.candy(new int[]{1,2,87,87,87,2,1}));
	}

}
